package com.cj.bookstore.pay;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

import java.io.FileWriter;
import java.io.IOException;

/**
 * 类名：AlipayConfig
 * 功能：基础配置类
 * 详细：设置帐户有关信息及返回路径
 */


@Component
@PropertySource(value = "classpath:zfbinfo.properties", encoding = "utf-8")
public class AlipayConfig {

    //↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


    // 支付宝网关
    private String openApiDomain;

    // 应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
    private String appId;

    // 商户私钥，您的PKCS8格式RSA2私钥
    private String merchantPrivateKey;

    // 支付宝公钥,查看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
    private String alipayPublicKey;

    // 服务器异步通知页面路径  需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    private String notifyUrl;

    // 页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
    private String returnUrl;

    // 签名方式
    private String signType;

    // 字符编码格式
    private String charset;

    private String logPath;

    private String format;


//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

    /**
     * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
     *
     * @param sWord 要写入日志里的文本内容
     */


    public void logResult(String sWord) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(logPath + "alipay_log_" + System.currentTimeMillis() + ".txt");
            writer.write(sWord);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (writer != null) {
                try {
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public String getOpenApiDomain() {
        openApiDomain = "https://openapi.alipaydev.com/gateway.do";
        return openApiDomain;
    }

    public void setOpenApiDomain(String openApiDomain) {
        this.openApiDomain = openApiDomain;
    }

    public String getAppId() {
        appId = "2021000118671353";
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getMerchantPrivateKey() {
        merchantPrivateKey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDFgoa/Y3HKvKNuwlKdQUR2dJcXurZNFHg8K7JeDg6TPdI1QNPlN7cKvgDe82EfUZu0hNiNVq9JXa28us0oREfeIuz0dPzLGmrRNWoO34f/2H47h2Ql5lXxrqyoXt+UT+hPO8hHnsGOWrFXo0Dhr0rKBdLIEFUiIlzeAQABMxYoSEj8cSTWkzKdCvWdDWU0VcXiiD2+BHWxMLsHGm8dZHTlAxC/J0Yu7HpY8vME1TsI9gy5MrEx6kjXquNIm7I76jDzYmYDQpj9o1bLwGXwYQ+VIn2yL1UF45wBChlv3ihhJYApZfAHQ6hAe9+o/Y9H5mopvw31pJcT/hk5xrWEHGkFAgMBAAECggEAbUiJkkBN6CV0MIao+4XvgbOFHoYa9I9M784lxVD105azRu/1zrCDQRhclwAHTzLyenG++IVsO6Xvyat6dLtDILAmeCR6805MqDFr24rnTzLUtc92JFpMV4uU0RydjQyht6WWbbpz0nZwBdO4xKcfNKUAOd5/nIFy7QuUmxVPPz22g614Y52ORLPkXUNLgYPB7X8I00c2d1sxFlnm/LrAq1lGeEDJkqs2+rF057oFmo2z/STzDY3hVQRVX7m2KDJ3y3i1WMbxkoagG+MdRwPEVV7BUNJZHhCums8eJo/ViTfvpH7T/RImnuIJHJbYpoZGoptR0JL2mTVoVlVDH15miQKBgQDvPyFm5XfmZ+0rUZTusb3kT16N0dRURmhQqWeXos1ihteUfYBywu8NL5ui4bhvSu6z6xkFQ+ZLfjkPjzweiHeyAXfZ1fQRBQrKQCjCp78iRtjA/o/6WT68cgOLn7C1CAPWeLQNgiimh+rhg/QeR6z0uXea+f1e/D5dG8qero8U4wKBgQDTVzMbcoaptGqUFQAEutJ7Gd6urYoodW5t1BjxuPUna1RgaowAB3CPGvbhQ0Uj0MGJU+PDGKK6gGNzX1qmbIyL3V5rlCo93JwWqIO1ALNa4QKDgbZpZegtEGPc2zDaSSbowkGTQQU8l4IRilgmDygDVT2a221VzIU6G2AdhblW9wKBgCy0aTNm8W6WQNT1W5T2lXsR8aMicECHH3rjDL5i52nftGzEvrmy/yRBnx1ifCofoFbyOSyosWGt5k+n/h3edi9G4vRLbF25yXhdYMBuw+JNxrbZWmH3RyfDTjJK1qQdKUpsJ4jWp23mu9cD5xu5XPIlrdnBmLyk+apARS49g/LtAoGBAJpPlTV5TfIjlZ5CJx1M+9p+bSXF+JbKB7ORphT5I6eAqr8rjMWIqRsUaSbZY2ZfSrDm2+rb1hWvIO5gtWPG5mhJXmPWb3Fz31R7/o7u0AaPPLKgx3v1uK0OxpvAP89iklJpZFAMrbIsPgBoryw67NBiMPUdOpvnFW/0BR4JQebJAoGADQ8Ziy1xC70JrIHXzgc1zbfIW54npXRw/hGifQsVWzKITejLg5oi+/3Finph4H0jxexPUiJz3+UdbnywT8+spGxK9KDZ6PudGxIq9MBFbJMODShxUeldYJ2p/RYpQkhrt+qY5EeFegQALfOqTWg0wm5cZ7E+h/i7xA8dkWrkkx8=";
        return merchantPrivateKey;
    }

    public void setMerchantPrivateKey(String merchantPrivateKey) {
        this.merchantPrivateKey = merchantPrivateKey;
    }

    public String getAlipayPublicKey() {
        alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApUYIPGt8tOff1lRvrN4n2ztzik4zT5sup3m0BWo9PLkmDES95CN9Jm5O0ipv3847dwkXdE9n0jj3+T/Vc/Sr6dFNsMebnOJ71YG28TUOylngjtZswhnO6UDKRGkSgAcQBHpV9g78MMbYXDFiecUKiOyTlAYHpzVjtR2sihIbuuGH93krI88lOrT7rdikASKKplvrUwnMFEiIfzqfYSQf5x7xBApYpk9R2MzkKrx7ZA8TJ433grsNr+56lyCWhimUplfzVOkHpHqXkib3DaGIkNHUo8g+oQBwTrZ2jFo6OnbopRAVhZYEN0RYCGPDKap6kDbT87vROtUSKAdWTI3R8QIDAQAB";
        return alipayPublicKey;
    }

    public void setAlipayPublicKey(String alipayPublicKey) {
        this.alipayPublicKey = alipayPublicKey;
    }

    public String getNotifyUrl() {
        notifyUrl = "http://localhost:8081/alipay.trade.page.pay-JAVA-UTF-8/notify_url.jsp";
        return notifyUrl;
    }

    public void setNotifyUrl(String notifyUrl) {
        this.notifyUrl = notifyUrl;
    }

    public String getReturnUrl() {
//        returnUrl = "http://localhost:8080/alipay.trade.page.pay-JAVA-UTF-8/return_url.jsp";
        return returnUrl;
    }

    public void setReturnUrl(String returnUrl) {
        this.returnUrl = returnUrl;
    }

    public String getSignType() {
        signType = "RSA";
        return signType;
    }

    public void setSignType(String signType) {
        this.signType = signType;
    }

    public String getCharset() {
        return charset;
    }

    public void setCharset(String charset) {
        this.charset = charset;
    }

    public String getLogPath() {
        return logPath;
    }

    public void setLogPath(String logPath) {
        this.logPath = logPath;
    }

    public String getFormat() {
        return format;
    }

    public void setFormat(String format) {
        this.format = format;
    }
}

